

import up from '../../assets/images/up.jpg';
import up_active from '../../assets/images/up_active.jpg';
import info from '../../assets/images/info.jpg';
import info_active from '../../assets/images/info_active.jpg';
import user from '../../assets/images/user.jpg';
import user_active from '../../assets/images/user_active.jpg';
import down from '../../assets/images/down.jpg';
import down_active from '../../assets/images/down_active.jpg';
import {getPanUserInfo,logout} from '../../api/index.js'
Page({
  data() {
    return {
      up,
      up_active,
      info,
      info_active,
      user,
      user_active,
      down,
      down_active,
      panType:'',
      userInfo:{},
      barStyle: {
        'background': '#fff',
        "border-radius": '4px'

      },
      backStyle: {
        'background-color': '#dedede40'
      },
    }
  },
  methods: {
    changeBack(val) {
      console.log("选中的安妮===>", val);
    },
    
    logout(){
      this.$Modal.confirm({
        title: '提示',
        content: '确定要退出账号?',
        submitText: '确定',
        cancelText: '取消',
        onCancel: () => {
         
        },
        onSubmit: () => {
          logout({
            panType:this.panType
          }).then((res)=>{
            if (res.data.code === 500&&res.data.msg==='用户登录已超时，请重新登录') {
              ok.clearH5AppStorage().then(res=>{
                this.$router.replace('/pages/login/index')
              })
              .catch(err=> {
                console.log("接口调用异常",err);
              });
              return
            }
              this.$router.replace({ path: '/pages/entrance/index' })
              
         
          })
        }
      })
      
    },

    numberConversion(str){
      let unitObj = {
        "KB":1024,
        "MB":1024*1024,
        "GB":1024*1024*1024,
        "TB":1024*1024*1024*1024,
        "PB":1024*1024*1024*1024*1024,
      }
      let unit = str.slice(-2)
      let num = Number(str.slice(0,-2)) 
      return unitObj[unit] * num
    }


  },
  mounted() {
    ok.getH5AppStorage({
      key: 'panType'
    }).then(res => {
      this.panType = res.data.data
      // console.log(typeof this.panType,'this.panType')
      getPanUserInfo({
        panType:res.data.data
      }).then((res)=>{
        this.userInfo = res.data.data
        let number = (this.numberConversion(this.userInfo.mainUsedSizeName)/this.numberConversion(this.userInfo.mainTotalSizeName))*100
        let result = number.toFixed(2)
        this.userInfo.percent = parseFloat(result)
        console.log("百分比=>",result)
        // console.log('总空间==>',this.numberConversion(this.userInfo.mainTotalSizeName))
        // console.log('已使用空间==>',this.numberConversion(this.userInfo.mainUsedSizeName))

        if (res.data.code === 500&&res.data.msg==='用户登录已超时，请重新登录') {
       
          ok.clearH5AppStorage().then(res=>{
            this.$router.replace('/pages/login/index')
          })
          .catch(err=> {
            console.log("接口调用异常",err);
          });
        }
      })
    }).catch(err => {
      console.log("接口调用异常", err);
    });
   
  }
});
